package com.das.metrocloud.ssoserver.controller;

import com.das.framework.web.spring.controller.*;
import org.springframework.beans.factory.annotation.*;
import com.das.metrocloud.ssoserver.service.*;
import com.das.cloud.system.service.*;
import com.das.cloud.system.entity.*;
import com.das.framework.common.extvo.*;
import com.das.framework.common.exception.*;
import com.das.framework.common.redis.utils.*;
import org.springframework.web.bind.annotation.*;
import java.util.*;

@RestController
@RequestMapping({ "/auth/resources" })
public class UserResourcesController extends SupportController
{
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private UserResourcesService userResourcesService;
    @Autowired
    private SysPermissionService sysPermissionService;
    public static List<SysPermissionEntity> sharePermissionList;
    
    @RequestMapping({ "/menu" })
    @ResponseBody
    public ResultVO menu() throws NotAuthorizationException {
        final ResultVO resultVO = new ResultVO();
        resultVO.setData((Object)this.userResourcesService.getCacheMenu(super.getLoginUserId()));
        return resultVO;
    }
    
    @RequestMapping({ "/permission" })
    @ResponseBody
    public ResultVO permission() throws NotAuthorizationException {
        final ResultVO resultVO = new ResultVO();
        Map<Object, Object> sharePermission = (Map<Object, Object>)this.redisUtils.hmget("SYS_SHARE_PERMISSION");
        if (sharePermission == null) {
            sharePermission = new HashMap<Object, Object>();
        }
        final Map<Object, Object> myPermission = (Map<Object, Object>)this.redisUtils.hmget(RedisCacheKeyUtils.userPermissionKey(super.getLoginUserId()));
        sharePermission.putAll(myPermission);
        resultVO.setData((Object)sharePermission);
        return resultVO;
    }
    
    @RequestMapping({ "/permission/web" })
    @ResponseBody
    public ResultVO permissionWeb() throws NotAuthorizationException {
        final ResultVO resultVO = new ResultVO();
        Map<Object, Object> sharePermission = (Map<Object, Object>)this.redisUtils.hmget("SYS_SHARE_PERMISSION_WEB");
        if (sharePermission == null) {
            sharePermission = new HashMap<Object, Object>();
        }
        final Map<Object, Object> myPermission = (Map<Object, Object>)this.redisUtils.hmget(RedisCacheKeyUtils.userPermissionWebKey(super.getLoginUserId()));
        sharePermission.putAll(myPermission);
        resultVO.setData((Object)sharePermission);
        return resultVO;
    }
    
    @RequestMapping({ "/sync" })
    @ResponseBody
    public ResultVO sync(@RequestBody final List<SysPermissionEntity> list) {
        final ResultVO resultVO = new ResultVO();
        this.sysPermissionService.savePermissionList((List)list);
        resultVO.setMessage("\u6743\u9650\u540c\u6b65\u6210\u529f.");
        return resultVO;
    }
    
    @RequestMapping({ "/sync-shared" })
    @ResponseBody
    public ResultVO syncShare() {
        final ResultVO resultVO = new ResultVO();
        this.userResourcesService.saveSharePermissionToRedis((String)null);
        resultVO.setMessage("\u540c\u6b65\u5171\u4eab\u6743\u9650\u6210\u529f.");
        return resultVO;
    }
    
    static {
        UserResourcesController.sharePermissionList = new ArrayList<SysPermissionEntity>();
    }
}
